package com.laozhao.EasySales;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;

import org.pushingpixels.substance.api.SubstanceLookAndFeel;
import org.pushingpixels.substance.api.skin.OfficeBlue2007Skin;

import com.laozhao.EasySales.view.MainWindowsFrame;
import com.laozhao.dreamframe.util.FrameFactory;
import com.laozhao.dreamframe.util.ToolsUtil;

/**
 * 
 */

/**
 * @author LaoZhao
 *
 */
public class StartPage {

	public static void main(String[] args) {

		JFrame.setDefaultLookAndFeelDecorated(true);
		JDialog.setDefaultLookAndFeelDecorated(true);

		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
//				SubstanceLookAndFeel.setSkin(new BusinessBlackSteelSkin());
				SubstanceLookAndFeel.setSkin(new OfficeBlue2007Skin());
				try {
					
					final MainWindowsFrame mainWindow = FrameFactory.setMainFrame(MainWindowsFrame.class);
					mainWindow.setTitle("销售系统");
					mainWindow.setVisible(true);

					mainWindow.setLocationRelativeTo(mainWindow.getOwner());
					mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
					mainWindow.setIconImage(Toolkit.getDefaultToolkit().createImage(
							StartPage.class.getResource("icon.png")));
//					mainWindow.setIconImage(new ImageIcon(ToolsUtil.getRoot() + "\\img\\icon.gif").getImage());
//					mainWindow.setIconImage(Toolkit.getDefaultToolkit().createImage(
//							MainWindowsControl.class.getResource("icon.png")));
					mainWindow.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
					mainWindow.addWindowListener(new WindowAdapter() {
						public void windowClosing(WindowEvent e) {
							int flag = JOptionPane.showConfirmDialog(mainWindow,
									"Sure to close?", "Care!",
									JOptionPane.YES_NO_OPTION,
									JOptionPane.INFORMATION_MESSAGE);
							if (JOptionPane.YES_OPTION == flag) {
								System.exit(0);
							} else {
								return;
							}
						}
					});
					mainWindow.init();
					ToolsUtil.setToCenter(mainWindow);

				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
}
